package com.mall.shopping.services;

import com.mall.shopping.IContentService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.converter.ContentConverter;
import com.mall.shopping.dal.entitys.PanelContent;
import com.mall.shopping.dal.persistence.PanelContentMapper;
import com.mall.shopping.dto.NavListResponse;
import com.mall.shopping.dto.PanelContentDto;
import com.mall.shopping.utils.ExceptionProcessorUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

import static com.mall.shopping.constant.GlobalConstants.HEADER_PANEL_ID;

/**
 * @Name : IContentServiceImpl.java
 * @Time : 2021/8/25 16:54
 * @Author : Xfeng
 * @Software : IntelliJ IDEA
 */

@Service
@Slf4j
public class IContentServiceImpl implements IContentService {

    @Autowired
    private PanelContentMapper panelContentMapper;

    @Autowired
    private ContentConverter contentConverter;

    @Override
    public NavListResponse queryNavList() {
        NavListResponse response = null;
        try {
            List<PanelContent> panelContents = panelContentMapper.selectPanelContent(HEADER_PANEL_ID);
            List<PanelContentDto> panelContentDtos = contentConverter.panelContent2Dto(panelContents);
            response = new NavListResponse();
            response.setPannelContentDtos(panelContentDtos);
            response.setCode(ShoppingRetCode.SUCCESS.getCode());
            response.setMsg(ShoppingRetCode.SUCCESS.getMessage());
        } catch (Exception e) {
            log.error("IContentServiceImpl.queryNavList occur Exception :" + e);
            ExceptionProcessorUtils.wrapperHandlerException(response, e);
        }
        return response;
    }
}
